<template>
	<u-swiper name='dishImage' :height="height" :list="swiperList"></u-swiper>
	<u-divider margin-top="20" margin-bottom="20" color="#F3AF28" class="u-divider">热门推荐</u-divider>
	<view class="u-wrap">
		<u-waterfall v-model="flowList" ref="uWaterfall1">
			<template v-slot:left="{leftList}">
				<view class="demo-warter" v-for="(item, index) in leftList" :key="index">
					<!-- 警告：微信小程序中需要hx2.8.11版本才支持在template中结合其他组件，比如下方的lazy-load组件 -->
					<u-lazy-load @click="toDetails(item)" threshold="-450" border-radius="10"
						:image="item.dishImage.split(',')[0]" :index="index"></u-lazy-load>
					<view class="demo-title">
						{{item.dishName}}
					</view>
					<view class="price-item">
						<view class="demo-price">
							{{item.specs[0].dishPrice}}元
						</view>
						<view class="demo-title">
							/份
						</view>
						<image @click="toDetails(item)" class="caring" :src="caring"></image>
					</view>
				</view>
			</template>
			<template v-slot:right="{rightList}">
				<view class="demo-warter" v-for="(item, index) in rightList" :key="index">
					<u-lazy-load @click="toDetails(item)" threshold="-450" border-radius="10"
						:image="item.dishImage.split(',')[0]" :index="index"></u-lazy-load>
					<view class="demo-title">
						{{item.dishName}}
					</view>
					<view class="price-item">
						<view class="demo-price">
							{{item.specs[0].dishPrice}}元
						</view>
						<view class="demo-title">
							/份
						</view>
						<image @click="toDetails(item)" class="caring" :src="caring"></image>
					</view>
				</view>
			</template>
		</u-waterfall>
	</view>
</template>

<script setup>
	import {
		onLoad
	} from '@dcloudio/uni-app';
	import {
		getSwiperListApi,
		getHotListApi
	} from '../../api/home.js'
	import {
		userLogin
	} from '../../api/user.js'
	import {
		ref
	} from 'vue';
	const height = ref('400')
	const caring = ref('/static/添加购物车.png')
	//定义轮播图
	const swiperList = ref([])
	//列表数据
	const flowList = ref([])

	//获取轮播图数据		
	const getSwiperList = async () => {
		let res = await getSwiperListApi()
		//console.log(res)
		if (res && res.code == 200) {
			swiperList.value = res.data
		}
	}
	//获取首页热推数据
	const getHotList = async () => {
		let res = await getHotListApi()
		//console.log(res)
		if (res && res.code == 200) {
			flowList.value = res.data
		}
	}
	onLoad(() => {
		getSwiperList()
		getHotList()
		userLogin()
	})
	//跳转详情
	const toDetails = (item) => {
		uni.navigateTo({
			url: '../detail/detail?goods=' + JSON.stringify(item)
		});
	}
</script>

<style>
	/* 	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	} */
	.u-wrap {
		padding: 0px 4px;
	}

	.demo-warter {
		border-radius: 8px;
		margin: 5px;
		background-color: #ffffff;
		padding: 5px;
		position: relative;
	}

	.u-close {
		position: absolute;
		top: 32rpx;
		right: 32rpx;
	}

	.demo-image {
		width: 100%;
		border-radius: 4px;
	}

	.demo-title {
		font-size: 22rpx;
		margin-top: 5px;
		color: $u-main-color;
	}

	.demo-tag {
		display: flex;
		margin-top: 5px;
	}

	.demo-tag-owner {
		background-color: $u-type-error;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		padding: 4rpx 14rpx;
		border-radius: 50rpx;
		font-size: 20rpx;
		line-height: 1;
	}

	.demo-tag-text {
		border: 1px solid $u-type-primary;
		color: $u-type-primary;
		margin-left: 10px;
		border-radius: 50rpx;
		line-height: 1;
		padding: 4rpx 14rpx;
		display: flex;
		align-items: center;
		border-radius: 50rpx;
		font-size: 20rpx;
	}

	.demo-price {
		font-size: 22rpx;
		color: #FF7670;
		margin-top: 5px;
	}

	.demo-shop {
		font-size: 22rpx;
		color: $u-tips-color;
		margin-top: 5px;
	}

	.price-item {
		display: flex;
		align-items: center;
	}

	.caring {
		height: 30rpx;
		width: 35rpx;
		margin-top: 5px;
		margin-bottom: 5px;
		margin-left: 10px;
	}
</style>